#ifndef DATAEXPORTER_H
#define DATAEXPORTER_H

#include <QObject>
#include <QSqlTableModel>
#include <QString>

class DataExporter : public QObject
{
    Q_OBJECT

public:
    explicit DataExporter(QObject *parent = nullptr);
    
    enum ExportFormat {
        CSV,
        JSON,
        XML,
        SQL
    };
    Q_ENUM(ExportFormat)
    
    bool exportTable(QSqlTableModel *model, const QString &filename, ExportFormat format);
    bool exportQueryResults(QSqlQueryModel *model, const QString &filename, ExportFormat format);
    
signals:
    void exportProgress(int percentage);
    void exportFinished(const QString &message);
    void exportError(const QString &error);

private:
    bool exportToCSV(QSqlTableModel *model, const QString &filename);
    bool exportToJSON(QSqlTableModel *model, const QString &filename);
    bool exportToXML(QSqlTableModel *model, const QString &filename);
    bool exportToSQL(QSqlTableModel *model, const QString &filename);
    
    bool exportQueryToCSV(QSqlQueryModel *model, const QString &filename);
    bool exportQueryToJSON(QSqlQueryModel *model, const QString &filename);
    bool exportQueryToXML(QSqlQueryModel *model, const QString &filename);
    bool exportQueryToSQL(QSqlQueryModel *model, const QString &filename);
    
    QString escapeCSVField(const QString &field) const;
};

#endif // DATAEXPORTER_H